//
//  QRCodeCardViewController.m
//  weibo
//
//  Created by hp on 16/4/27.
//  Copyright © 2016年 hp. All rights reserved.
//

#import "QRCodeCardViewController.h"
#import "QRCode.h"
#import "UIImage+RoundedRectImage.h"

@interface QRCodeCardViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *codeImageView;

@end

@implementation QRCodeCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 1、创建要生成二维码的字符串
    NSString *source = @"Hello World";
    // 2、创建一个CIImage
    CIImage *imgQRCode = [QRCode createQRCodeImage:source];
    // 3、 生成UIImage
    UIImage *img = [QRCode resizeQRCodeImage:imgQRCode withSize:self.codeImageView.frame.size.width];
    // 调整二维码颜色
    img = [QRCode specialColorImage:img withRed:100 green:100 blue:100];
    // 中间贴张图片
    UIImage *photoImg = [UIImage createRoundedRectImage:[UIImage imageNamed:@"baidu_icon"] withSize:CGSizeMake(50, 50) withRadius:30];
    img = [QRCode addIconToQRCodeImage:img withIcon:photoImg withIconSize:photoImg.size];
    
    self.codeImageView.image = img;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
